import { $ } from "./Game";

// Tree 的 runtime 代码
// 从屏幕外的一个位置丢下一颗树，赋予向左的初速度，然后自由下落到地面，出屏幕时进行销毁
export default class Tree extends Laya.Sprite {
    constructor() {
        super();
    }
    RigidBody: Laya.RigidBody;

    onEnable() {
        this.pos(2400, 200);
        this.RigidBody = this.getComponent(Laya.RigidBody);
        this.changeSpeed();
        this.timer.loop(100, this, this.isOver);
    }
    changeSpeed() {
        this.RigidBody.linearVelocity = {
            x: -$.speed,
            y: 0,
        };
    }
    isOver() {
        if (this.x < -100) {
            this.clearTimer(this, this.isOver);
            this.destroy();
        }
    }
}
